﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BBRILCSharp.ViewModels;
using Net.JGLI.RilSharp;

namespace BBRILCSharp.Views
{
    /// <summary>
    /// Interaction logic for MainView.xaml
    /// </summary>
    public partial class MainView : Window
    {
        public MainView()
        {
            InitializeComponent();

            this.ContentRendered += new EventHandler(MainView_ContentRendered);
        }

        void MainView_ContentRendered(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            MainViewModel viewModel = this.DataContext as MainViewModel;
            LoginWnd loginWnd = new LoginWnd();

            loginWnd.DataContext = this.DataContext;
            loginWnd.Owner = this;
            loginWnd._chkAutoLogOn.IsChecked = viewModel.UserModel.IsAutoLogOn;
            loginWnd._chkRemeberMe.IsChecked = viewModel.UserModel.IsRememberMe;
            loginWnd._txtUserName.Text = viewModel.UserModel.UserName;
            loginWnd._password.Password = viewModel.UserModel.Password;

            this.Hide();

            loginWnd.Show();
        }

        private void _btnMakeAs_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.

            RilListItem item = (RilListItem)((sender as Button).DataContext);
            MainViewModel viewModel = this.DataContext as MainViewModel;
            viewModel.MakeAsReadOrUnRead(item);
        }

        private void _btnAbout_Click(object sender, RoutedEventArgs e)
        {
            About aboutWnd = new About();
            aboutWnd.Owner = this;
            aboutWnd.ShowDialog();
        }

        private void _btnSetting_Click(object sender, RoutedEventArgs e)
        {
            Setting settingWnd = new Setting();
            settingWnd.DataContext = this.DataContext;
            settingWnd.Owner = this;
            settingWnd.ShowDialog();
        }

        private void _btnAddPageToList_Click(object sender, System.Windows.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
            NewRilPage page = new NewRilPage();
            page.DataContext = this.DataContext;
            page.Owner = this;
            page.ShowDialog();
        }
    }
}
